/* 
 * @description: 按钮组件样式
 * @author: Jane 
 * @date: 2023-09-12 17:03:57
 */

import 'package:basic_common/app_theme.dart';
import 'package:basic_common/screen_helper.dart';
import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';

/// 圆角按钮
Widget roundBtn(
    {required String text,
    required Function()? onTap,
    Color textColor = AppTheme.dartTextColor,
    Color bgColor = AppTheme.primyColor,
    Color borderColor = AppTheme.primyColor,
    bool isEnable = true,
    double width = 120}) {
  return SizedBox(
    width: width,
    child: Row(
      children: [
        Expanded(
          child: ElevatedButton(
            onPressed: isEnable ? onTap : null,
            child: Text(
              text,
              style: TextStyle(color: textColor),
            ),
            style: ButtonStyle(
              elevation: MaterialStateProperty.all(0),

              //将按钮背景设置为透明
              backgroundColor: MaterialStateProperty.all(
                  isEnable ? bgColor : AppTheme.hintTextColor),
              shape: MaterialStateProperty.all<StadiumBorder>(
                StadiumBorder(
                  side: BorderSide(
                      color: isEnable ? borderColor : AppTheme.hintTextColor),
                  // borderRadius: BorderRadius.circular(50),
                ),
              ),
            ),
          ),
        ),
      ],
    ),
  );
}

/// 宽度平铺按钮
/// onPressed 按钮事件
/// textStr 文本内容
Widget btnComponent({
  required void Function()? onPressed,
  bool isEnable = false,
  required String textStr,
}) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      Expanded(
          child: ElevatedButton(
        onPressed: isEnable ? onPressed : null,
        style: ElevatedButton.styleFrom(
            backgroundColor:
                isEnable ? AppTheme.primyColor : AppTheme.hintTextColor),
        child: Text(
          textStr,
          style: const TextStyle(color: Colors.white),
        ),
      ))
    ],
  );
}

/// 常用功能Item项
/// icon 图标
/// title 标题名称
Widget buildTopImgItem(
    {required String icon,
    required String title,
    double width = 51,
    double height = 5,
    Color? svgBgColor,
    String? packageName,
    bool isSvg = false}) {
  return Column(
    crossAxisAlignment: CrossAxisAlignment.center,
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      isSvg
          ? Container(
              width: ScreenHelper.width(width),
              height: ScreenHelper.width(width),
              padding: EdgeInsets.all(8),
              decoration: svgBgColor != null
                  ? BoxDecoration(
                      color: svgBgColor, borderRadius: BorderRadius.circular(4))
                  : BoxDecoration(borderRadius: BorderRadius.circular(4)),
              child: SvgPicture.asset(
                icon,
                width: ScreenHelper.width(width),
                height: ScreenHelper.width(width),
                package: "basic_common",
              ),
            )
          : Image.asset(
              icon,
              package: "basic_common",
              width: ScreenHelper.width(width),
              height: ScreenHelper.width(width),
              
              
            ),
      SizedBox(
        height: height,
      ),
      Text(
        title,
        style: TextStyle(
            color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(13)),
      )
    ],
  );
}

/// 选择项目
Widget selectItem(
    {required String text, Color textColor = AppTheme.hintTextColor}) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.end,
    children: [
      Expanded(
        child: Text(
          text,
          // softWrap: true,
          // maxLines: 1,
          overflow: TextOverflow.ellipsis,
          textAlign: TextAlign.end,
          style: TextStyle(
              color: text.contains("请选择") ? textColor : AppTheme.dartTextColor,
              fontSize: ScreenHelper.sp(16)),
        ),
      ),
      Icon(
        Icons.keyboard_arrow_down,
        color: AppTheme.hintTextColor,
        size: ScreenHelper.width(24),
      )
    ],
  );
}

/// 性别选择组件
Widget buildGenderCheck({required String title, bool isChecked = false}) {
  return Row(
    crossAxisAlignment: CrossAxisAlignment.center,
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      Image.asset(
        isChecked
            ? "assets/register/icon_checked.png"
            : "assets/register/icon_uncheck.png",
            package: "basic_common",
        width: ScreenHelper.width(21),
        height: ScreenHelper.width(21),
      ),
      SizedBox(
        width: ScreenHelper.width(10),
      ),
      Text(
        title,
        style: TextStyle(
            color: AppTheme.dartTextColor, fontSize: ScreenHelper.sp(16)),
      )
    ],
  );
}


/// 圆角按钮
Widget connerButton({
  required void Function()? onPressed,
  required String textStr,
  Color textColor = AppTheme.dartTextColor,
  Color bgColor = AppTheme.primyColor,
  Color borderColor = AppTheme.primyColor,
}) {
  return Row(
    mainAxisAlignment: MainAxisAlignment.center,
    children: [
      Expanded(
          child: ElevatedButton(
        onPressed: onPressed,
        style: ElevatedButton.styleFrom(
            elevation: 0,
            backgroundColor: bgColor,
            side: BorderSide(color: borderColor)),
        child: Text(
          textStr,
          style: TextStyle(color: textColor),
        ),
      ))
    ],
  );
}


